package com.feshfans.controller.special;

import com.feshfans.controller.Controller;
import com.feshfans.controller.StageManager;
import com.feshfans.xmpp.client.ClientFactory;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
import com.feshfans.xmpp.client.AccountClient;


public class LoginController extends Controller {

    private AccountClient accountClient;

    @FXML private TextField username;
    @FXML private PasswordField password;
    @FXML private GridPane gridPane;


    private Stage settingsStage;

    public LoginController(){
        this.accountClient = ClientFactory.getClient(ClientFactory.ClientType.Account);
    }

    @FXML
    protected void loginAction(ActionEvent event){

        String usernameText = username.getText();
        String passwordText = password.getText();
        accountClient.login(usernameText,passwordText);

        StageManager.openOrGetMainStage();
        //关闭本窗口
        Stage currentStage = (Stage)gridPane.getScene().getWindow();
        currentStage.close();
    }

    @FXML
    protected void settingAction(ActionEvent event){

        try {
            Parent root = FXMLLoader.load(getClass().getResource("/fxml/Settings.fxml"));
            settingsStage = new Stage();
            settingsStage.setTitle("MyIM Settings");
            settingsStage.setScene(new Scene(root, 300, 300));
            settingsStage.show();
            //设置默认值

        }catch (Exception e){
            e.printStackTrace();
        }

    }

}
